//
//  JuGeneric.swift
//  JuSwift
//
//  Created by Juvid on 2018/6/7.
//  Copyright © 2018年 Juvid. All rights reserved.
//

import UIKit
//泛型
class JuGeneric: NSObject {
    func start()  {
        var someString = "hello"
        var anotherString = "world"

        var someInt = 3
        var anotherInt = 4

        swapTwoValues(&someString, &anotherString)
        swapTwoValues(&someInt, &anotherInt)
        swaTValues(3, 4)
        swaTValues("aaa", "bbb")
        swaValues("aaa", NSString("234"))
//        var path = TestStruct(segmentEnd: ["111"])
//        path.segmentEnd = ["fsafd"]
//        swaValues("aaa", 222)

    }
    func swapTwoInts( a: inout Int, _ b: inout Int) {
        let temporaryA = a
        a=b
        b = temporaryA
    }

    func swapTwoValues <T> (_ a: inout T, _ b: inout T) {
        let temporaryA = a
        a=b
        b = temporaryA
    }
//    泛型的同一组变量<T>多个变量为同一种类型
    func swaTValues <T> (_ a:  T, _ b:  T) {
//        let temporaryA = a
//        let temporaryB = b
        print(a)
        print(b)
    }
//    Any 的多个变量可以为任意不同类型
    func swaValues  (_ a:  Any, _ b: AnyObject) {
//        let temporaryA = a
//        let temporaryB = b
        print(a)
         print(b)
    }

}

struct TestStruct {
    var segments = ""
    let segmentEnd: [String]
//    var isEmpty: Bool {
//        segments.isEmpty
//    }
}
//extension TestKeyPath {
//    init(_ keyPath: String) {
////        segments = keyPath.components(separatedBy: ".")
//    }
//}
